﻿using System;

using Spencen.Mobile.Markup;
using Spencen.Mobile.UI;
using Spencen.Mobile.UI.Commanding;
using Spencen.Mobile.UI.Controls;
using Spencen.Mobile.UI.Primitives;
using Spencen.Mobile.UI.Navigation;

namespace Demo.Presenters
{
    public class WelcomePresenter
    {
        private INavigator _navigator;
        private IDrawingHost _host;

        public WelcomePresenter( INavigator navigator )
        {
            DragDemoCommand = new DelegateCommand( DragDemo );
            LayoutDemoCommand = new DelegateCommand( LayoutDemo );
            PrimitivesDemoCommand = new DelegateCommand( PrimitivesDemo );
            AnimationDemoCommand = new DelegateCommand( AnimationDemo );
            InteropDemoCommand = new DelegateCommand( InteropDemo );
            _navigator = navigator;
        }

        public DelegateCommand DragDemoCommand { get; private set; }
        public DelegateCommand LayoutDemoCommand { get; private set; }
        public DelegateCommand PrimitivesDemoCommand { get; private set; }
        public DelegateCommand AnimationDemoCommand { get; private set; }
        public DelegateCommand InteropDemoCommand { get; private set; }

        public View CreateView( IDrawingHost host )
        {
            _host = host;

            // XAML Loading
            var text = (System.IO.Stream) System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( "Demo.Views.WelcomeView.xml" );
            var xamlRenderer = new XamlRenderer( _host, this );
            var view = (View)xamlRenderer.Render( text );

            return view;
        }

        private void DragDemo()
        {
            var dragPresenter = new DragPresenter( _navigator );
            _navigator.Forward( dragPresenter.CreateView( _host ) );
        }

        private void LayoutDemo()
        {
            var layoutPresenter = new LayoutPresenter( _navigator );
            _navigator.Forward( layoutPresenter.CreateView( _host ) );
        }

        private void PrimitivesDemo()
        {
            var presenter = new PrimitivesPresenter( _navigator );
            _navigator.Forward( presenter.CreateView( _host ) );
        }

        private void AnimationDemo()
        {
            var presenter = new AnimationPresenter( _navigator );
            _navigator.Forward( presenter.CreateView( _host ) );
        }

        private void InteropDemo()
        {
            var presenter = new InteropPresenter( _navigator );
            _navigator.Forward( presenter.CreateView( _host ) );
        }
    }
}
